package paf.importerandtranslators;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import org.xml.sax.SAXException;

import paf.model.DiagramExpressionModel;

public class FileImportController implements ActionListener{
	//private FileStrategy fileTypeToImport;
	private DiagramExpressionModel model = DiagramExpressionModel.get();
	private Interpretation interpretedInstructions;
	
	protected FileImportController(){
		interpretedInstructions = new Interpretation();
	}
	
	public void importFile(FileStrategy type, File file) throws SAXException, IOException{
		interpretedInstructions = type.interpret(file);
		executeInstructions(interpretedInstructions.getDiagramType());
	}
	
	public void executeInstructions(String diagramType){
		if(diagramType.equalsIgnoreCase("UML - Class")){
			System.out.println("klasDiagram gedetecteerd");
			for(int i = 0; i < interpretedInstructions.getInterpretedExpressions().size(); i++){
				if(!interpretedInstructions.getInterpretedExpressions().get(i).equalsIgnoreCase("  ")){
					model.createConnectionClass(interpretedInstructions.getInterpretedExpressions().get(i));
				}
			}
			model.updateModel();
			
		}
		else if(diagramType.equalsIgnoreCase("Flowchart - Ellipse")){
			for(int i = 0; i<interpretedInstructions.getInterpretedExpressions().size(); i++){
				if(!interpretedInstructions.getInterpretedExpressions().get(i).equalsIgnoreCase(" ")){
					model.createConnectionUseCase(interpretedInstructions.getInterpretedExpressions().get(i));
				}
			}
		}
	}

	@Override
	public void actionPerformed(ActionEvent event) {
		// TODO Auto-generated method stub
		
	}
}
